#include "AIAlignment.h"
#include "Agent.h"

AIAlignment::AIAlignment()
{

}

void AIAlignment::Update()
{
	Neighbours n = m_agent->GetNeighbours();
	int numOfNeighbours = n.size();
	
	D3DXVECTOR3 heading;	
	for (int i = 0; i != numOfNeighbours; i++)
	{
		heading += n[i]->GetPosition();
	}
	heading *= (1.0f / (float)numOfNeighbours);

	// head towards average of neighbours
	D3DXVECTOR3 direction = heading - m_agent->GetPosition();
	m_agent->AddForce(direction);
}